package com.hospital.diagnosis.module.exception.enums;

/**
 * 全局错误码枚举
 *
 * 一般情况下，使用 HTTP 响应状态码 https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Status
 */
public enum ExceptionCode {

    // ========== 通用错误段 ==========

    SUCCESS(200, "成功"),
    FAILURE(500, "失败"),

    // ========== 客户端错误段 ==========

    BAD_REQUEST(400, "请求参数不正确"),
    UNAUTHORIZED(401, "账号未登录"),
    USER_NOT_EXIST(401,"用户名不存在"),
    INCORRECT_PASSWORD(401,"密码输入错误，请核实，并检查大小写锁定、数字锁定是否开启。"),
    IP_ADDRESS_UNAUTHORIZED(401,"IP地址不在登录许可范围"),
    FORBIDDEN(403, "没有该操作权限"),
    NOT_FOUND(404, "请求未找到"),
    METHOD_NOT_ALLOWED(405, "请求方法不正确"),
    NOT_ACCEPTABLE(406, "请求头中Accept不支持"),
    REQUEST_TIMEOUT(408, "请求超时"),
    CONFLICT(409, "请求冲突"),
    UNSUPPORTED_MEDIA_TYPE(415, "请求头中Content-Type不支持"),
    REQUEST_ENTITY_TOO_LARGE(413, "请求数据过大"),
    LOCKED(423, "请求失败，请稍后重试"), // 并发请求，不允许
    RETRY_WITH(449,"操作失败，请稍后再试"),
    TOO_MANY_REQUESTS(429, "请求过于频繁，请稍后重试"),
    BIZ_ERROR(430, "业务错误"),

    // ========== 服务端错误段 ==========

    INTERNAL_SERVER_ERROR(500, "系统异常"),
    NOT_IMPLEMENTED(501, "功能未实现/未开启"),
    ERROR_CONFIGURATION(502, "错误的配置项"),

    // ========== 自定义错误段 ==========
    IMPORT_RECORD_FAILED(449,"导入记录失败"),
    TABLE_NO_RECORD(410,"表内无数据"),
    UPLOAD_FILE_FAILED(449,"上传文件失败"),
    RECORD_NOT_FOUND(404,"记录未找到"),
    REPEATED_REQUESTS(900, "重复请求，请稍后重试"), // 重复请求
    DEMO_DENY(901, "演示模式，禁止写操作"),
    UNKNOWN(999, "未知错误");


    private Integer code;
    private String message;

    /**
     * 单参构造，仅传入错误信息
     * 错误码统一为2000
     * @param message 错误信息
     */
    ExceptionCode(String message){
        this.code=2000;
        this.message=message;
    }

    ExceptionCode(Integer code,String message){
        this.code=code;
        this.message=message;
    }

    public String getMessage(){
        return this.message;
    }

    public Integer getCode(){
        return  this.code;
    }

}
